import server from '../server/http'

// 获取分类的结构
var getTypes = function() {
    return new Promise((resolve, reject) => {
        server.get('/json/fenlei.json').then(res => {
            resolve(res)
        })
    })
}

// 获取列表数据
var getLists = function(id) {
    return new Promise((resolve, reject) => {
        server.get('/json/list.json').then(res => {
            // console.log(res.data)
            let list = res.data.result
            var arr = []
            list.map((item, index, array) => {
                // console.log(item, index)
                // 筛选出满足当前tab条件的列表数据
                if(item.cid == id) {
                    arr.push(item)
                }
            })
            // console.log(arr)
            resolve(arr)
        })
    })
}

// 获取详情数据
var getDetail = function(id) {
    return new Promise((resolve, reject) => {
        server.get('/json/list.json').then(res => {
            // resolve(res)
            let list = res.data.result
            for(var i = 0; i<  list.length; i++) {
                if(list[i]._id === id) {
                    resolve(list[i])
                    break
                }
            }
        })
    })
}

// 导出api请求方法
export {
    getTypes,
    getLists,
    getDetail
}